package com.my.quartz.hello;

import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;

/**
 * @Author ScholarTang
 * @Date 2021/7/13 19:53
 * @Desc 全局任务监听器
 */
@Slf4j
public class MyJobListener implements JobListener {
    @Override
    public String getName() {
        String name = this.getClass().getSimpleName();
        log.info("[监听器]当前JobListener的名称为：" + name);
        return name;
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        String name = context.getJobDetail().getJobClass().getName();
        log.info("[监听器]当前Job的名称为：" + name + "，JobDetail将要被执行了...");
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {
        String name = context.getJobDetail().getJobClass().getName();
        log.info("[监听器]当前Job的名称为：" + name + "，JobDetail将要被执，但被TriggerListener否决...");
    }

    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        String name = context.getJobDetail().getJobClass().getName();
        log.info("[监听器]当前Job的名称为：" + name + "，JobDetail执行完成了...");
    }
}
